package polygon.cli.util;

import polygon.util.impl.PostParameter;
import polygon.util.impl.UnsafeFileUtil;
import polygon.util.FileUtil;
import polygon.util.ZipUtil;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * @author MikeMirzayanov (mirzayanovmr@gmail.com)
 */
public class StatementsUtil {
    public static byte[] download(URL url, String login, String password) throws IOException {
        PostParameter[] postParameters = new PostParameter[2];

        postParameters[0] = new PostParameter("login", login);
        postParameters[1] = new PostParameter("password", password);

        return UnsafeFileUtil.downloadFileAsByteArray(url.toString(),
                Integer.MAX_VALUE, postParameters);
    }

    public static boolean looksLikePdf(byte[] bytes) {
        if (bytes == null || bytes.length < 16) {
            return false;
        }

        String header = new String(bytes, 0, 4);
        return header.equalsIgnoreCase("%PDF");
    }
}
